package com.mis.geoEncryption.model.listerners;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import com.mis.geoEncryption.model.connect.DatabaseConnector;
 
/**
 * Application Lifecycle Listener implementation class MainServletListener 
 *
 */
public class MainServletListener  implements ServletContextListener {
	/******************************
	 * properties
	 *****************************/
	
	/**Username of the DB**/
	private static String USERNAME = "username";
	
	/**Password of the DB**/
	private static String PASSWORD = "password";
	
	/**Name of the DB**/
	private static String DBNAME = "database"; 
 
	/**
     * @see ServletContextListener#contextInitialized(ServletContextEvent)
     */
    public void contextInitialized(ServletContextEvent event) {
 
    	ServletContext sc = event.getServletContext();
 
    	String url = sc.getInitParameter("url");
    	String user_name = sc.getInitParameter(MainServletListener.USERNAME);
    	String password = sc.getInitParameter(MainServletListener.PASSWORD);
    	String database = sc.getInitParameter(MainServletListener.DBNAME);
    	DatabaseConnector db = new DatabaseConnector(url + database, user_name, password);
    	//System.out.println("in the listener!!");
    	sc.setAttribute("db", db);
 
    }
 
	/**
     * @see ServletContextListener#contextDestroyed(ServletContextEvent)
     */
    public void contextDestroyed(ServletContextEvent arg0) {
        // TODO Auto-generated method stub
    }
 
}
